package manager{
	import data.Tower;
	
	import events.GameEvent;
	
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	
	import view.BuildBar;
	import view.BuildSelect;

	public class TdManage extends Sprite{
		
		/**
		 * 单历模式 
		 */		
		private static var _instance:TdManage;
		/**
		 * 生成时间对象 
		 */		
		private var timer:Timer;
		
		/**
		 * 当前地图所存放的塔的 数组 
		 */		
		public var towers:Array=[];
		
		/**
		 * 声明塔的类型选择对象 
		 */		
		private var buildBar:BuildBar = BuildBar.getInstence();
		public static function getInstance():TdManage{
			if(!_instance){
				_instance = new TdManage();
			}
			return _instance;
		}
		public function TdManage(){
			
			timer = new Timer(40);
			timer.addEventListener(TimerEvent.TIMER,timerHandle);
			timer.start();
			
			//侦听建筑物选择器上的建筑物选择器的单击事件
			buildBar.addEventListener(GameEvent.CLICK_BUILD_TYPE,creatBuildDataHandle);
		}
		
		private function timerHandle(event:TimerEvent):void{
			//doSomething			
		}
		
		/**
		 * 创建塔的数据 
		 * @param event
		 * 
		 */
		private function creatBuildDataHandle(event:GameEvent):void{
			var obj:Object = event.obj;
			var tower:Tower = new Tower(obj);
			towers.push(tower);
			//创建一个搭（数据）后发送一个搭的显示事件
			var evt:GameEvent = new GameEvent(GameEvent.CREAT_BUILD_VIEW,tower);
			buildBar.dispatchEvent(evt);
		}
		
	}
}